package com.shejimoshi.单例模式.深浅克隆.深克隆.实现cloneAble进行深度复制;

public class Food {
    private String name;
    private int weight;

    public Food(String name, int weight) {
        this.name = name;
        this.weight = weight;
    }

    @Override
    protected Object clone() throws CloneNotSupportedException {
        Food food = null;
        try{
            food = (Food) super.clone();
        } catch (Exception e) {
            System.out.println("Food对象深度赋值失败！");
        }

        return food;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getWeight() {
        return weight;
    }

    public void setWeight(int weight) {
        this.weight = weight;
    }

    @Override
    public String toString() {
        return "Food{" +
                "name='" + name + '\'' +
                ", weight=" + weight +
                '}';
    }
}
